using UnityEngine;

public class GravityFlight
{
	public float timeOfFlight;

	public Vector3 initialPosition { get; protected set; }

	public Vector3 initialVelocity { get; protected set; }

	public Vector3 gravity { get; protected set; }

	public bool active { get; set; }

	public float apexTime
	{
		get
		{
			if (gravity.y == 0f)
			{
				return 0f;
			}
			return (0f - initialVelocity.y) / gravity.y;
		}
	}

	public void Fire(Vector3 position, Vector3 velocity, Vector3 gravity)
	{
		initialPosition = position;
		initialVelocity = velocity;
		this.gravity = gravity;
		timeOfFlight = 0f;
		active = true;
	}

	public Vector3 Position(float time)
	{
		return new Vector3(ParabolaPosition(initialPosition.x, initialVelocity.x, gravity.x, time), ParabolaPosition(initialPosition.y, initialVelocity.y, gravity.y, time), ParabolaPosition(initialPosition.z, initialVelocity.z, gravity.z, time));
	}

	protected float ParabolaPosition(float s0, float v0, float g, float time)
	{
		return s0 + g * 0.5f * time * time + v0 * time;
	}

	public Vector3 Velocity(float time)
	{
		return initialVelocity + gravity * time;
	}

	public float timeToReachHeight(float height)
	{
		MathEx.NullPoints nullPoints = MathEx.FindParabolaNullPoints(gravity.y * 0.5f, initialVelocity.y, initialPosition.y - height);
		if (nullPoints.nullPts.Count == 0)
		{
			return -1f;
		}
		return nullPoints.Max;
	}
}
